﻿
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Web.UI;
using System.Web.UI.WebControls;

using DotNetNuke;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using System.Data;
using System.Data.SqlClient;

using Common;
namespace eMarketing
{
    partial class SearcheMarketing : PortalModuleBase, IActionable
    {
        #region Private Members

        private int loc_UserID;

        //use for ddlSearchArea
        //private string loc_SearchArea_All_Value         = Common.consts.constCbNoneItemValue;//"All";
        //private string loc_SearchArea_All_Text          = Common.consts.constCbNoneItemText;//"Tất cả";
        private string loc_SearchArea_BuyProduct_Value  = Common.consts.constProfileProduct;//"P_";
        private string loc_SearchArea_BuyProduct_Text   = "Chào bán";
        private string loc_SearchArea_SellRequest_Value = Common.consts.constProfileBuyRequest;//"B_";
        private string loc_SearchArea_SellRequest_Text  = "Tìm mua";
        private string loc_SearchArea_Enterprise_Value  = Common.consts.constProfileEnterprise;//"E_";
        private string loc_SearchArea_Enterprise_Text   = "Doanh nghiệp";

        //use for ddlOrderBy
        private string loc_OrderBy_Interesting_Contacting_Number_Value  = "1";
        private string loc_OrderBy_Interesting_Contacting_Number_Text   = "Số quan tâm + liên hệ";
        private string loc_OrderBy_Interesting_Click_Number_Value       = "2";
        private string loc_OrderBy_Interesting_Click_Number_Text        = "Số quan tâm + click";
        private string loc_OrderBy_Contacting_Click_Number_Value        = "3";
        private string loc_OrderBy_Contacting_Click_Number_Text         = "Số liên hệ + click";

        data.userDataSetTableAdapters.tm_group_memberTableAdapter groupMemberTA = new data.userDataSetTableAdapters.tm_group_memberTableAdapter();
        data.userDataSet.tm_group_memberDataTable groupMemberTbl = new data.userDataSet.tm_group_memberDataTable();
        data.userDataSet.tm_group_memberRow groupMemberRow;

        ArrayList loc_arActivityCat = new ArrayList();
        ArrayList loc_arProductCat  = new ArrayList();

        #endregion

        #region Event Handlers

        protected void Page_Load(System.Object sender, System.EventArgs e)
        {
            try
            {
                lblMessage.Visible = false;
                lblAddMemberMes.Visible = false;
                //groupMemberTA.Connection.ConnectionString = sysLibs.GetConnectionString;
                    
                hplFromDate.NavigateUrl = DotNetNuke.Common.Utilities.Calendar.InvokePopupCal(txtFromDate);
                hplToDate.NavigateUrl = DotNetNuke.Common.Utilities.Calendar.InvokePopupCal(txtToDate);

                if (!Page.IsPostBack)
                {
                    loc_UserID = UserId;

                    #region treeview
                    tvProductCatS.textFldName = "description1";
                    tvProductCatS.valueFldName = "code";
                    tvProductCatS.dataTableName = "tm_productCat";
                    tvProductCatS.parentFldName = "parentcode";

                    tvActivityCat.textFldName = "description1";
                    tvActivityCat.valueFldName = "code";
                    tvActivityCat.dataTableName = "tm_activityCat";
                    tvActivityCat.parentFldName = "parentcode";

                    //set grouplist width
                    tm_GroupList_Search.MyWidth = 200;
                    tm_GroupList_Search.MyHeight = 100;
                    #endregion treeview
 
                    PageLoadData();
                
                    if (Session["SearchedData"] != null)
                        Session.Remove("SearchedData");
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }

        }

        #endregion

        #region Optional Interfaces

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Registers the module actions required for interfacing with the portal framework
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public ModuleActionCollection ModuleActions
        {
            get
            {
                ModuleActionCollection Actions = new ModuleActionCollection();
                Actions.Add(this.GetNextActionID(), Localization.GetString(ModuleActionType.AddContent, this.LocalResourceFile), ModuleActionType.AddContent, "", "", this.EditUrl(), false, SecurityAccessLevel.Edit, true, false);
                return Actions;
            }
        }

        #endregion

        //OK1
        private void PageLoadData()
        {
            ShowListSearchArea();
            ShowOrder();
            //ShowUserIDInTextBox();
        }

        //OK1
        private bool ValidateSearchInformation()
        {
            if ((txtFromDate.Text.Trim() != "" && txtToDate.Text.Trim() == "") ||
                (txtFromDate.Text.Trim() == "" && txtToDate.Text.Trim() != ""))
            {
                sysLibs.ShowErrorNotice(lblMessage, "Ngày tháng không hợp lệ");
                return false;
            } 
            
            if (txtFromDate.Text.Trim() != "" && !sysLibs.StringIsValidDateTime(txtFromDate.Text.Trim()))
            {
                sysLibs.ShowErrorNotice(lblMessage, "Ngày tháng không hợp lệ");
                return false;
            }

            if (txtToDate.Text.Trim() != "" && !sysLibs.StringIsValidDateTime(txtToDate.Text.Trim()))
            {
                sysLibs.ShowErrorNotice(lblMessage, "Ngày tháng không hợp lệ");
                return false;
            }

            int tmp = 0;
            if (txtInterestingNumber.Text.Trim() != "" && !int.TryParse(txtInterestingNumber.Text, out tmp))
            {
                sysLibs.ShowErrorNotice(lblMessage, "Số quan tâm không hợp lệ");
                return false;
            }
            if (txtContactingNumber.Text.Trim() != "" && !int.TryParse(txtContactingNumber.Text, out tmp))
            {
                sysLibs.ShowErrorNotice(lblMessage, "Số liên hệ không hợp lệ");
                return false;
            }

            if (txtClickNumber.Text.Trim() != "" && !int.TryParse(txtClickNumber.Text, out tmp))
            {
                sysLibs.ShowErrorNotice(lblMessage, "Số lượt click chuột không hợp lệ");
                return false;
            }
            return true;
        }
        
        //OK1
        private void ShowListSearchArea()
        {
            try
            {
                //ddListSearchArea.Items.Add(new ListItem(loc_SearchArea_All_Text, loc_SearchArea_All_Value));
                ddListSearchArea.Items.Add(new ListItem(loc_SearchArea_BuyProduct_Text, loc_SearchArea_BuyProduct_Value));
                ddListSearchArea.Items.Add(new ListItem(loc_SearchArea_SellRequest_Text, loc_SearchArea_SellRequest_Value));
                ddListSearchArea.Items.Add(new ListItem(loc_SearchArea_Enterprise_Text, loc_SearchArea_Enterprise_Value));
            }
            catch(Exception exc)
            {
                string mess = exc.Message; 
            }
        }

        //OK1
        private void ShowOrder()
        {
            try
            {
                ddlOrderBy.Items.Add(new ListItem(loc_OrderBy_Contacting_Click_Number_Text, loc_OrderBy_Contacting_Click_Number_Value));
                ddlOrderBy.Items.Add(new ListItem(loc_OrderBy_Interesting_Click_Number_Text, loc_OrderBy_Interesting_Click_Number_Value));
                ddlOrderBy.Items.Add(new ListItem(loc_OrderBy_Interesting_Contacting_Number_Text, loc_OrderBy_Interesting_Contacting_Number_Value));
            }
            catch (Exception exc)
            {
                string mess = exc.Message;
            }
        }

        //OK1
        private string SearchEMarketingQueryString()
        {
            string query = "";

            try
            {
                ArrayList arSelectedNodes = null;
                if (ddListSearchArea.SelectedValue.Equals(consts.constProfileEnterprise))
                    arSelectedNodes = sysLibs.Translate(sysLibs.getSelectedNodes(tvActivityCat.myTreeView), "tm_activityCat", "code", "syscodeId");
                else
                    arSelectedNodes = sysLibs.Translate(sysLibs.getSelectedNodes(tvProductCatS.myTreeView), "tm_productCat", "code", "syscodeId");
                string area = "";
                if (arSelectedNodes != null)
                {
                    IEnumerator enu = arSelectedNodes.GetEnumerator();
                    while (enu.MoveNext())
                        area += enu.Current.ToString() + ",";
                    area = area.Substring(0,area.LastIndexOf(","));
                }

                string fromDate = "", toDate = "";

                if (txtFromDate.Text.Trim() != "" && txtToDate.Text.Trim() != "")
                {
                    fromDate = sysLibs.ConvertToSQLDateString(txtFromDate.Text.Trim());
                    toDate = sysLibs.ConvertToSQLDateString(DateTime.Parse(txtToDate.Text.Trim()).AddDays(1));
                }

                string searchArea = ddListSearchArea.SelectedValue;

                query += " SELECT a.userid, CASE WHEN userType & " + sysLibs.turnBitOn(0, consts.constENTBitPos) + ">0 THEN companyName1 ELSE fullName END AS name1, " +
                         "                  sum(quantam) as quantam, sum(lienhe) as lienhe, sum(click) as click ";
                query+=  " FROM ( ";

                //tm_product
                if (searchArea.Equals(consts.constProfileProduct))
                {
                    query += "      SELECT senderId as userId,0 as quantam,count(*) as lienhe, 0 as click " +
                            "       FROM tm_messages INNER JOIN tm_product ON tm_messages.infoId = tm_product.productId " +
                            "                        INNER JOIN tm_product_syscodes ON tm_product.productId = tm_product_syscodes.productId" +
                            "       WHERE messageType='" + searchArea + "' AND senderId Is not null ";
                    if (!fromDate.Equals("") && !toDate.Equals(""))
                        query += "      AND onDate BETWEEN '" + fromDate + "' AND '" + toDate + "' ";
                    if (!area.Equals(""))
                        query += "      AND tm_product_syscodes.syscodeId in ("+ area +") ";
                    
                    query += "          GROUP BY senderId " +
                    "           UNION ALL ( " +
                    "               SELECT userid,count(*) as quantam,0 as lienhe,0 as click " +
                    "               FROM tm_user_profiles INNER JOIN tm_product ON tm_user_profiles.infoId = tm_product.productId" +
                    "                                     INNER JOIN tm_product_syscodes ON tm_product_syscodes.productId = tm_product.productId " +
                    "               WHERE infoType = '" + searchArea + "' ";
                    if (!fromDate.Equals("") && !toDate.Equals(""))
                        query += "      AND onDate BETWEEN '" + fromDate + "' AND '" + toDate + "' ";
                    if (!area.Equals(""))
                        query += "      AND tm_product_syscodes.syscodeId in (" + area + ") ";

                    query += "          GROUP BY userId ) " +
                    "           UNION ALL ( " +
                    "               SELECT userid,0 as quantam , 0 as lienhe,count(*) as click " +
                    "               FROM tm_click_counter INNER JOIN tm_product ON tm_product.productId = tm_click_counter.infoId " +
                    "                                     INNER JOIN tm_product_syscodes ON tm_product_syscodes.productId = tm_product.productId " +
                    "               WHERE type = '" + searchArea + "' AND userId > 0 ";
                    if (!fromDate.Equals("") && !toDate.Equals(""))
                        query += "      AND onTime BETWEEN '" + fromDate + "' AND '" + toDate + "' ";
                    if (!area.Equals(""))
                        query += "      AND tm_product_syscodes.syscodeId in (" + area + ") ";
                    query += "          GROUP BY userid ) ) a, tm_users ";
                }

                //tm_buy_request
                if (searchArea.Equals(consts.constProfileBuyRequest))
                {
                    query += "      SELECT senderId as userId,0 as quantam,count(*) as lienhe, 0 as click " +
                            "       FROM tm_messages INNER JOIN tm_buy_request ON tm_messages.infoId = tm_buy_request.requestId " +
                            "                        INNER JOIN tm_buy_request_syscodes ON tm_buy_request.requestId = tm_buy_request_syscodes.requestId" +
                            "       WHERE messageType='" + searchArea + "' AND senderId Is not null ";
                    if (!fromDate.Equals("") && !toDate.Equals(""))
                        query += "      AND onDate BETWEEN '" + fromDate + "' AND '" + toDate + "' ";
                    if (!area.Equals(""))
                        query += "      AND tm_buy_request_syscodes.syscodeId in (" + area + ") ";

                    query += "          GROUP BY senderId " +
                    "           UNION ALL ( " +
                    "               SELECT userid,count(*) as quantam,0 as lienhe,0 as click " +
                    "               FROM tm_user_profiles INNER JOIN tm_buy_request ON tm_user_profiles.infoId = tm_buy_request.requestId" +
                    "                                     INNER JOIN tm_buy_request_syscodes ON tm_buy_request_syscodes.requestId = tm_buy_request.requestId " +
                    "               WHERE infoType = '" + searchArea + "' ";
                    if (!fromDate.Equals("") && !toDate.Equals(""))
                        query += "      AND onDate BETWEEN '" + fromDate + "' AND '" + toDate + "' ";
                    if (!area.Equals(""))
                        query += "      AND tm_buy_request_syscodes.syscodeId in (" + area + ") ";

                    query += "          GROUP BY userId ) " +
                    "           UNION ALL ( " +
                    "               SELECT userid,0 as quantam , 0 as lienhe,count(*) as click " +
                    "               FROM tm_click_counter INNER JOIN tm_buy_request ON tm_buy_request.requestId = tm_click_counter.infoId " +
                    "                                     INNER JOIN tm_buy_request_syscodes ON tm_buy_request_syscodes.requestId = tm_buy_request.requestId " +
                    "               WHERE type = '" + searchArea + "' AND userId > 0 ";
                    if (!fromDate.Equals("") && !toDate.Equals(""))
                        query += "      AND onTime BETWEEN '" + fromDate + "' AND '" + toDate + "' ";
                    if (!area.Equals(""))
                        query += "      AND tm_buy_request_syscodes.syscodeId in (" + area + ") ";
                    query += "          GROUP BY userid ) ) a, tm_users ";
                }

                //tm_enterprises
                if (searchArea.Equals(consts.constProfileEnterprise))
                {
                    query += "      SELECT senderId as userId,0 as quantam,count(*) as lienhe, 0 as click " +
                            "       FROM tm_messages INNER JOIN tm_users ON tm_users.userId = tm_messages.infoId " +
                            "                        INNER JOIN tm_user_syscodes ON tm_users.userId = tm_user_syscodes.userId " +
                            "       WHERE messageType='" + searchArea + "' AND senderId Is not null ";
                    if (!fromDate.Equals("") && !toDate.Equals(""))
                        query += "      AND onDate BETWEEN '" + fromDate + "' AND '" + toDate + "' ";
                    if (!area.Equals(""))
                        query += "      AND tm_user_syscodes.syscodeId in (" + area + ") ";

                    query += "          GROUP BY senderId " +
                    "           UNION ALL ( " +
                    "               SELECT tm_user_profiles.userid,count(*) as quantam,0 as lienhe,0 as click " +
                    "               FROM tm_user_profiles INNER JOIN tm_users ON tm_users.userId = tm_user_profiles.infoId " +
                    "                                     INNER JOIN tm_user_syscodes ON tm_users.userId = tm_user_syscodes.userId " +
                    "               WHERE infoType = '" + searchArea + "' ";
                    if (!fromDate.Equals("") && !toDate.Equals(""))
                        query += "      AND onDate BETWEEN '" + fromDate + "' AND '" + toDate + "' ";
                    if (!area.Equals(""))
                        query += "      AND tm_user_syscodes.syscodeId in (" + area + ") ";

                    query += "          GROUP BY tm_user_profiles.userId ) " +
                    "           UNION ALL ( " +
                    "               SELECT tm_click_counter.userid,0 as quantam , 0 as lienhe,count(*) as click " +
                    "               FROM tm_click_counter INNER JOIN tm_users ON tm_users.userId = tm_click_counter.infoId " +
                    "                                     INNER JOIN tm_user_syscodes ON tm_users.userId = tm_user_syscodes.userId" +
                    "               WHERE type = '" + searchArea + "' AND tm_click_counter.userId > 0 ";
                    if (!fromDate.Equals("") && !toDate.Equals(""))
                        query += "      AND onTime BETWEEN '" + fromDate + "' AND '" + toDate + "' ";
                    if (!area.Equals(""))
                        query += "      AND tm_user_syscodes.syscodeId in (" + area + ") ";
                    query += "          GROUP BY tm_click_counter.userid ) ) a, tm_users ";
                }
              
                query += " WHERE a.userid = tm_users.userId ";

                //tim kiem theo quan tam
                string interestingNumber = txtInterestingNumber.Text.Trim();
                if (interestingNumber != "")
                    query += " AND quantam >= " + interestingNumber;
                //tim kiem theo lien he
                string contactingNumber = txtContactingNumber.Text.Trim();
                if (contactingNumber != "")
                    query += " AND lienhe >= " + contactingNumber; 
                //tim kiem theo click
                string clickNumber = txtClickNumber.Text.Trim();
                if (clickNumber != "")
                    query += " AND click >= " + clickNumber;



                query += " GROUP BY a.userid,fullName,companyName1,userType ";

                //sap xep theo
                string orderByValue = ddlOrderBy.SelectedValue;
                switch (orderByValue)
                {
                    case "1":
                        query += " ORDER BY quantam, lienhe ";
                        break;
                    case "2":
                        query += " ORDER BY quantam,click ";
                        break;
                    case "3":
                        query += " ORDER BY lienhe, click ";
                        break;
                }
            }
            catch(Exception exc)
            {
                string mess = exc.Message;
            }

            return query;
        }

        //OK1
        private void DoSearch()
        {
            SqlConnection connection = null;
            DataTable dt = new DataTable();
            try
            {
                string strQuery = SearchEMarketingQueryString();
                //sysLibs.ShowNotice(lblMessage, strQuery, false);
                //return;
                connection = new SqlConnection(sysLibs.GetConnectionString);
                SqlDataAdapter adapter = new SqlDataAdapter(strQuery, connection);
                connection.Open();
                adapter.Fill(dt);

                gvSearch.DataSource = dt;
                gvSearch.DataBind();

                //user for add alll
                Session["SearchedData"] = dt;
            }
            catch (Exception exc)
            {
                string mess = exc.Message;
            }
            finally
            {
                if (connection != null)
                    connection.Close();
            }
        }

        //OK1
        private bool InsertSelectedSearchMembers()
        {
            bool result = false;
            try
            {
                ArrayList arSelectedNodes = tm_GroupList_Search.GetSelectedNodesArray();

                if (arSelectedNodes != null)
                {
                    for (int groupIdx = 0; groupIdx < arSelectedNodes.Count; groupIdx++)
                    {
                        for (int memberIdx = 0; memberIdx < gvSearch.Rows.Count; memberIdx++)
                        {
                            CheckBox ck = (CheckBox)gvSearch.Rows[memberIdx].FindControl("ck");
                            if (ck.Checked)
                            {
                                Label lblID = (Label)gvSearch.Rows[memberIdx].FindControl("lblID");
                                groupMemberTbl = groupMemberTA.GetDataByGroupMember(int.Parse(arSelectedNodes[groupIdx].ToString()), int.Parse(lblID.Text));
                                if (groupMemberTbl.Rows.Count <= 0)
                                    InsertMember(int.Parse(arSelectedNodes[groupIdx].ToString()), int.Parse(lblID.Text), DateTime.Now);
                            }
                        }
                        result = true;
                    }
                }
            }
            catch (Exception exc)
            {
                string mess = exc.Message;
                result = false;
            }
            return result;
        }

        //OK1
        private bool InsertAllSearchMembers()
        {
            bool result = false;
            try
            {
                ArrayList arSelectedNodes = tm_GroupList_Search.GetSelectedNodesArray();
                if (arSelectedNodes != null)
                {
                    DataTable dt = (DataTable)Session["SearchedData"];
                    Session.Remove("SearchedData");

                    for (int groupIdx = 0; groupIdx < arSelectedNodes.Count; groupIdx++)
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            groupMemberTbl = groupMemberTA.GetDataByGroupMember(int.Parse(arSelectedNodes[groupIdx].ToString()), int.Parse(dr["userid"].ToString()));
                            if (groupMemberTbl.Rows.Count <= 0)
                                InsertMember(int.Parse(arSelectedNodes[groupIdx].ToString()), int.Parse(dr["userid"].ToString()), DateTime.Now);
                        }
                    }
                    result = true;   
                }
            }
            catch (Exception exc)
            {
                string mess = exc.Message;
                result = false;
            }
            return result;
        }

        //OK1
        private bool ValidateHasSelectedSearchMember()
        {
            for (int i = 0; i < gvSearch.Rows.Count; i++)
            {
                CheckBox ck = (CheckBox)gvSearch.Rows[i].FindControl("ck");
                if (ck.Checked == true)
                    return true;
            }
            return false;
        }
  
        //OK1
        private bool ValidateHasSelectSearchGroup()
        {
            ArrayList arGroup = new ArrayList();
            arGroup = tm_GroupList_Search.GetSelectedNodesArray();
            if (arGroup != null && arGroup.Count>0)
                return true;
            return false;
        }

        //OK1
        private bool ValidateHasAllMember()
        {
            if (Session["SearchedData"] != null)
                return true;

            return false;
        }

        //OK1
        private void InsertMember(int groupID, int memberId,DateTime datetime)
        {
            try
            {
                groupMemberRow = groupMemberTbl.Newtm_group_memberRow();
                groupMemberRow.groupId = groupID;
                groupMemberRow.memberId = memberId;
                groupMemberRow.createOn = datetime;
                groupMemberTbl.Addtm_group_memberRow(groupMemberRow);
                groupMemberTA.Update(groupMemberTbl);
            }
            catch (Exception exc)
            {
                string mess = exc.Message;
            }
        }

        //OK1
        protected void btnSearchInfo_Search_Click(object sender, EventArgs e)
        {
            gvSearch.PageIndex = 0;
            if (ValidateSearchInformation())
                DoSearch();
        }
   
        //OK1
        protected void btnAddNewGroup_Click(object sender, EventArgs e)
        {
            Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(TabId, "group", "mid=" + ModuleId));
        }

        //OK1
        protected void btnAddSelectedItem_Click(object sender, EventArgs e)
        {
            if (ValidateHasSelectedSearchMember())
                if (ValidateHasSelectSearchGroup())
                    if (InsertSelectedSearchMembers())
                        sysLibs.ShowNotice(lblAddMemberMes, "Thêm thành viên vào nhóm thành công", false);
                    else
                        sysLibs.ShowNotice(lblAddMemberMes, "Thêm thành viên vào nhóm không thành công", true);
                else
                    sysLibs.ShowNotice(lblAddMemberMes, "Chọn nhóm", true);
            else
                sysLibs.ShowNotice(lblAddMemberMes, "Chọn thành viên", true);
        }

        //OK1
        protected void btnAddAllSelectedItem_Click(object sender, EventArgs e)
        {
            if (ValidateHasAllMember())
            {
                if (ValidateHasSelectSearchGroup())
                {
                    if (InsertAllSearchMembers())
                        sysLibs.ShowNotice(lblAddMemberMes, "Thêm thành viên vào nhóm thành công", false);
                    else
                        sysLibs.ShowNotice(lblAddMemberMes, "Thêm thành viên vào nhóm không thành công", true);
                }
                else
                    sysLibs.ShowNotice(lblAddMemberMes, "Chọn nhóm", true);
            }
            else
                sysLibs.ShowNotice(lblAddMemberMes, "Không có thành viên", true);
        }
   
        //OK1
        protected void gvSearch_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvSearch.PageIndex = e.NewPageIndex;
            DoSearch();
        }

        //OK1
        protected void gvSearch_DataBound(object sender, EventArgs e)
        {
            pnlGroup.Visible = (gvSearch.Rows.Count > 0);
        }

        //OK1
        protected void btnGroup_Click(object sender, EventArgs e)
        {
            Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(TabId,"group","mid=" + ModuleId));
        }
        protected void ddListSearchArea_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddListSearchArea.SelectedValue.Equals(consts.constProfileEnterprise))
            {
                tvProductCatS.Visible = false;
                tvActivityCat.Visible = true;
            }
            else
            {
                tvProductCatS.Visible = true;
                tvActivityCat.Visible = false;
            }
        }
}
}

